#include<iostream>
#include<fstream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,cnt=0,bh;
struct fwq{
	int a,b,c,d,e;
}fwqs[1010];
bool pd(fwq a){
	for(int i=1;i<=cnt;i++){
		if(fwqs[i].a==a.a&&fwqs[i].b==a.b&&fwqs[i].c==a.c&&fwqs[i].d==a.d&&fwqs[i].e==a.e){
			bh=i;
			return true;
		}
	}
	return false;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		char op[7];
		int a,b,c,d,e;
		scanf("%s %d.%d.%d.%d:%d",&op,&a,&b,&c,&d,&e);
		if(a<256&&b<256&&c<256&&d<256&&e<65535){
			fwq ad;
			ad.a=a;ad.b=b;ad.c=c;ad.d=d;ad.e=e;
			if(op[0]=='C'&&op[1]=='l'){
				if(pd(ad)){
					printf("%d\n",bh);
				}else{
					printf("FAIL\n");
				}
			}else{
				if(pd(ad)){
					printf("FAIL\n");
				}
				else{
					printf("OK\n");
					cnt++;
					fwqs[cnt]=ad;
				}
			}
		}else{
			printf("ERR\n");
		}
	}
	return 0;
}
